var http = require('http');
var httpProxy  = require('http-proxy');
var fs = require('fs');

var servers = JSON.parse(fs.readdirSync('server_list.json')).servers;

var s = httpProxy.createRightProxy(function (req, res, proxy) {
    var target = servers.shift();
    proxy.proxyRequest(req, res, target);
    servers.push(target);
})

s.listen(8080);